package com.mycompany.sigemp.repository.hibernate;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.mycompany.sigemp.model.Detalle;
import com.mycompany.sigemp.repository.DetalleRepository;

@Repository
public class HibernateDetalleRepository extends HibernateDaoSupport implements DetalleRepository {
	
	@Autowired
	public HibernateDetalleRepository(SessionFactory sessionFactory){
		setSessionFactory(sessionFactory);
	}

	@Override
	public void registrarDetalle(ArrayList<Detalle> lista) {
		for (Detalle detalle : lista) {
			getHibernateTemplate().saveOrUpdate(detalle);
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Detalle> obtenerDetallesDeUnPedido(String codigoPedido) {
		return getHibernateTemplate().find("from Detalle where codigoPedido='"+codigoPedido+"'");
	}

}
